<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Commodity extends Model
{
    public function setPicturesAttribute($pictures)
    {
        if (is_array($pictures)) {
            $this->attributes['pictures'] = json_encode($pictures);
        }
    }

    public function getPicturesAttribute($pictures)
    {
        return json_decode($pictures, true);
    }

    public function brand()
    {
        return $this->hasOne(Brand::class, 'id', 'brand_id');
    }
    public function type()
    {
        return $this->hasOne(CommodityType::class, 'id', 'commodity_type');
    }

    public function commodityattr()
    {
        return $this->hasMany(CommodityAttr::class,'commodity_id','id');
    }


    
    public function rentcloth()
    {
        return $this->hasOne(RentCloth::class,'commodity_id','id');
    }



   
}
